#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    stack<unsigned long long> stk;
    int n;
    cin >> n;
    while (n--) {
      char op[6];
      unsigned long long x;
      scanf("%s", op);
      if (strcmp(op, "push") == 0) {
        scanf("%llu", &x);
        stk.push(x);
      } else if (strcmp(op, "pop") == 0) {
        if (stk.empty()) {
          cout << "Empty" << endl;
        } else {
          stk.pop();
        }
      } else if (strcmp(op, "query") == 0) {
        if (stk.empty()) {
          cout << "Anguei!" << endl;
        } else {
          cout << stk.top() << endl;
        }
      } else {
        cout << stk.size() << endl;
      }
    }
  }
}